<html>
<style>
    .err{
        color:red;
    }
</style>

<body>

<?php
     $uniacid=$name=$password=$salt=$sex=$parent_id='';
     $department_id=$login_time=$err_login_count=$create_time='';

     $uniacid_err=$name_err=$password_err=$sex_err=$parent_id_err='';
     $department_id_err=$login_time_err=$err_login_count_err=$create_time_err='';

     function clean($data){
         $data=trim($data);
         $data=stripslashes($data);
         $data=htmlspecialchars($data);
         return $data;
     }
     echo "当前模式为",$_SERVER["REQUEST_METHOD"];

//     若状态为post则录入处理后的数据并进行为空判断
     if($_SERVER["REQUEST_METHOD"]=="POST")
     {
         $uniacid = clean($_POST["uniacid"]);
         $name = clean($_POST["name"]);
         $password = clean($_POST["password"]);
         $salt = clean($_POST["salt"]);
         $sex = clean($_POST["sex"]);
         $parent_id = clean($_POST["parent_id"]);
         $department_id = clean($_POST["department_id"]);
         $login_time = clean($_POST["login_time"]);
         $err_login_count = clean($_POST["err_login_count"]);
         $create_time = clean($_POST["create_time"]);

         $count = 0;
         if (empty($uniacid)) {
             $uniacid_err = "该项不能为空！";
         } else {
             $count++;
         }

         if (empty($name)) {
             $name_err = "该项不能为空！";
         } else {
             $count++;
         }

         if (empty($password)) {
             $password_err = "该项可以为空";
         }

         if (empty($salt)) {
             $salt_err = "该项不能为空！";
         } else {
             $count++;
         }

         if (empty($sex)) {
             $sex_err = "该项不能为空！";
         } else {
             $count++;
         }

         if (empty($parent_id)) {
             $parent_id_err = "该项不能为空！";
         } else {
             $count++;
         }

         if (empty($department_id)) {
             $department_id_err = "该项不能为空！";
         } else {
             $count++;
         }

         if (empty($login_time)) {
             $login_time_err = "该项不能为空！";
         } else {
             $count++;
         }

         if (empty($err_login_count)) {
             $err_login_count_err = "该项不能为空！";
         } else {
             $count++;
         }

         if (empty($create_time)) {
             $create_time_err = "该项不能为空！";
         } else {
             $count++;
         }

//       必填项全填完时action执行的site改为跳转到执行新增用户
         if ($count != 9) {
             $site = htmlspecialchars($_SERVER["PHP_SELF"]);
         }
         else{
             $site = "http://dev.lanti.com/index.php/pingtai/adminuser/test2";
         }
         $count2=9-$count;
         echo "，未填写的必填项数量为",$count2;
         if($count==9){
             echo "，再次点击提交进行录入！";
         }


     }




?>

<!--表单部分-->
<form action="<?php echo $site;?>" method="post">
    <p style="color=red">该表单用于录入一个新的管理账户的信息，*为必填项</p>
    uniacid:    <br><input type="text" name="uniacid" value="<?php echo $uniacid;?>">
    <span class="err"><?php echo "*",$uniacid_err;?></span>
    <br>
    name:       <br><input type="text" name="name" value="<?php echo $name;?>">
    <span class="err"><?php echo "*",$name_err;?></span>
    <br>
    password:   <br><input type="text" name="password" value="<?php echo $password;?>">
    <span style="color:aqua"><?php echo $password_err;?></span>
    <br>
    salt:       <br><input type="text" name="salt" value="<?php echo $salt;?>">
    <span class="err"><?php echo '*',$salt_err;?></span>
    <br><br>
    sex:        <input type="radio" name="sex" value="1" <?php if($sex==1){echo "checked";}?>>male
                <input type="radio" name="sex" value="2" <?php if($sex==2){echo "checked";}?>>female
    <span class="err"><?php echo "*",$sex_err;?></span>
    <br><br>
    parent_id:  <br><input type="text" name="parent_id" value="<?php echo $parent_id;?>">
    <span class="err"><?php echo "*",$parent_id_err;?></span>
    <br>
    department_id:<br><input type="text" name="department_id" value="<?php echo $department_id;?>">
    <span class="err"><?php echo "*",$department_id_err;?></span>
    <br>
    login_time:<br><input type="text" name="login_time" value="<?php echo $login_time;?>">
    <span class="err"><?php echo "*",$login_time_err;?></span>
    <br>
    err_login_count:<br><input type="text" name="err_login_count" value="<?php echo $err_login_count;?>">
    <span class="err"><?php echo "*",$err_login_count_err;?></span>
    <br>
    create_time:<br><input type="text" name="create_time" value="<?php echo $create_time;?>">
    <span class="err"><?php echo "*",$create_time_err;?></span>
    <br><br>
    <input type="submit" name="submit" value="submit">
</form>



</body>
</html>